package com.itheima.反射.Constructor.demo4;

import com.itheima.反射.Constructor.demo3.Student;

import java.lang.reflect.Constructor;

public class Demo {
    public static void main(String[] args) throws Exception {
        Class<?> aClass = Class.forName("com.itheima.反射.Constructor.demo3.Student");

        //基于公共的无参构造创建对象
        Student stu1 = (Student) aClass.newInstance();

        //基于任意权限修饰符的构造方法创建对象
        Constructor<?> con = aClass.getDeclaredConstructor(String.class);
        //暴力反射
        con.setAccessible(true);
        //基于构造器对象创建类的对象
        Student stu2 = (Student) con.newInstance("刘岩");

    }
}
